import 'package:auto_route/auto_route.dart';
import 'package:convergence_media/features/app/app.dart';
import 'package:convergence_media/features/circle/circle.dart';
import 'package:convergence_media/features/circle/features/follow/view/follow.dart';
import 'package:convergence_media/features/circle/features/local/view/local.dart';
import 'package:convergence_media/features/circle/features/video/view/video.dart';
import 'package:convergence_media/features/news/features/convergence/view/convergence.dart';
import 'package:convergence_media/features/news/features/information/view/information.dart';
import 'package:convergence_media/features/news/features/recommand/view/recommand.dart';
import 'package:convergence_media/features/news/news.dart';
import 'package:convergence_media/features/post/view/post.dart';
import 'package:convergence_media/features/service/features/government/view/government.dart';
import 'package:convergence_media/features/service/features/helper/view/helper.dart';
import 'package:convergence_media/features/service/service.dart';
import 'package:convergence_media/features/user/view/login.dart';
import 'package:convergence_media/features/user/view/me.dart';
import 'package:convergence_media/features/user/view/message.dart';
import 'package:convergence_media/features/user/view/score.dart';
import 'package:convergence_media/features/video/features/channel/view/channel.dart';
import 'package:convergence_media/features/video/features/live_streaming/view/live_streaming.dart';
import 'package:convergence_media/features/video/video.dart';
import 'package:convergence_media/navigator/auth_guard.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'app_router.gr.dart';
part 'app_router.g.dart';

@riverpod
AppRouter appRouter(AppRouterRef ref) =>
    AppRouter(authGuard: ref.watch(authGuardProvider));

@AutoRouterConfig(replaceInRouteName: 'Screen,Route')
class AppRouter extends _$AppRouter {
  AppRouter({
    required this.authGuard,
    super.navigatorKey,
  });

  @override
  RouteType get defaultRouteType => const RouteType.adaptive();

  final AuthGuard authGuard;

  @override
  List<AutoRoute> get routes {
    return [
      AutoRoute(
        path: '/main',
        page: MainRoute.page,
        initial: true,
        children: [
          AutoRoute(
            page: NewsRoute.page,
            path: 'news',
            children: [
              AutoRoute(
                page: NewsRecommandRoute.page,
                path: 'recommand',
                initial: true,
              ),
              AutoRoute(page: ConvergenceRoute.page, path: 'convergence'),
              AutoRoute(page: InformationRoute.page, path: 'information'),
            ],
          ),
          AutoRoute(
            page: VideoRoute.page,
            path: 'video',
            children: [
              RedirectRoute(path: '', redirectTo: VideoRecommandRoute.name),
              AutoRoute(page: VideoRecommandRoute.page, path: 'recommand'),
              AutoRoute(page: LiveStreamingRoute.page, path: 'live_streaming'),
              AutoRoute(page: ChannelRoute.page, path: 'channel'),
            ],
          ),
          AutoRoute(
            page: CircleRoute.page,
            path: 'circle',
            children: [
              RedirectRoute(path: '', redirectTo: FollowRoute.name),
              AutoRoute(page: FollowRoute.page, path: 'follow'),
              AutoRoute(page: CircleVideoRoute.page, path: 'circle_video'),
              AutoRoute(page: LocalRoute.page, path: 'local'),
            ],
          ),
          AutoRoute(
            page: ServiceRoute.page,
            path: 'service',
            children: [
              RedirectRoute(path: '', redirectTo: ServiceRecommandRoute.name),
              AutoRoute(page: ServiceRecommandRoute.page, path: 'recommand'),
              AutoRoute(page: GovernmentRoute.page, path: 'government'),
              AutoRoute(page: HelperRoute.page, path: 'helper'),
            ],
          ),
        ],
      ),
      AutoRoute(page: LoginRoute.page, path: '/login'),
      AutoRoute(
        page: MeRoute.page,
        path: '/me',
        children: [
          RedirectRoute(path: '', redirectTo: MessageRoute.name),
          AutoRoute(page: MessageRoute.page, path: 'message'),
          AutoRoute(page: ScoreRoute.page, path: 'score'),
        ],
        guards: [authGuard],
      ),
    ];
  }
}
